package com.nt.oam.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import com.nt.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.nt.common.annotation.Log;
import com.nt.common.core.controller.BaseController;
import com.nt.common.core.domain.AjaxResult;
import com.nt.common.enums.BusinessType;
import com.nt.oam.domain.AntSoftwareAsset;
import com.nt.oam.service.IAntSoftwareAssetService;
import com.nt.common.utils.poi.ExcelUtil;
import com.nt.common.core.page.TableDataInfo;

/**
 * 软件资产Controller
 *
 * @author JZFeng
 * @date 2025-02-05
 */
@RestController
@RequestMapping("/oam/software")
public class AntSoftwareAssetController extends BaseController {
    @Autowired
    private IAntSoftwareAssetService antSoftwareAssetService;

    /**
     * 查询软件资产列表
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:software:list')")
    @GetMapping("/list")
    public TableDataInfo list(AntSoftwareAsset antSoftwareAsset, Integer pageNum, Integer pageSize) {
        startPage();
        List<AntSoftwareAsset> list = antSoftwareAssetService.selectAntSoftwareAssetList(antSoftwareAsset);
        return getDataTable(list);
    }

    /**
     * 导出软件资产列表
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:software:export')")
    @Log(title = "软件资产", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AntSoftwareAsset antSoftwareAsset) {
        List<AntSoftwareAsset> list = antSoftwareAssetService.selectAntSoftwareAssetList(antSoftwareAsset);
        ExcelUtil<AntSoftwareAsset> util = new ExcelUtil<AntSoftwareAsset>(AntSoftwareAsset.class);
        util.exportExcel(response, list, "软件资产数据");
    }

    /**
     * 获取软件资产详细信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:software:query')")
    @GetMapping(value = "/{softwareAssetId}")
    public AjaxResult getInfo(@PathVariable("softwareAssetId") Long softwareAssetId) {
        return success(antSoftwareAssetService.selectAntSoftwareAssetBySoftwareAssetId(softwareAssetId));
    }

    /**
     * 新增软件资产
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:software:add')")
    @Log(title = "软件资产", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AntSoftwareAsset antSoftwareAsset) {
        return toAjax(antSoftwareAssetService.insertAntSoftwareAsset(antSoftwareAsset));
    }

    /**
     * 修改软件资产
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:software:edit')")
    @Log(title = "软件资产", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AntSoftwareAsset antSoftwareAsset) {
        return toAjax(antSoftwareAssetService.updateAntSoftwareAsset(antSoftwareAsset));
    }

    /**
     * 删除软件资产
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:software:remove')")
    @Log(title = "软件资产", businessType = BusinessType.DELETE)
    @DeleteMapping("/{softwareAssetIds}")
    public AjaxResult remove(@PathVariable Long[] softwareAssetIds) {
        return toAjax(antSoftwareAssetService.deleteAntSoftwareAssetBySoftwareAssetIds(softwareAssetIds));
    }

    /**
     * 非系统---获取软件资产详细信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:software:query')")
    @GetMapping(value = "/details/{softwareAssetId}")
    public AjaxResult getSoftwareMessage(@PathVariable("softwareAssetId") Long softwareAssetId) {
        return success(antSoftwareAssetService.selectSoftwareAsset(softwareAssetId));
    }

    /**
     * 获取页面是否在修改的状态
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:software:query')")
    @GetMapping(value = "/get/isModify")
    public AjaxResult getSoftwareModify(@RequestParam Long softwareAssetId) {
        return success(antSoftwareAssetService.selectSoftwareModify(softwareAssetId));
    }

    /**
     * 修改页面是否在修改的状态
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:software:edit')")
    @Log(title = "接入设备资产", businessType = BusinessType.UPDATE)
    @PostMapping("/edit/modify/{softwareAssetId}")
    public AjaxResult editModify(@PathVariable("softwareAssetId") Long softwareAssetId) {
        int isModify = 1;
        return toAjax(antSoftwareAssetService.updateSoftwareModify(softwareAssetId, isModify));
    }
}
